<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <li :class="{ completed: item.isDone }" v-for="item in list" :key="item.id">
      <div class="view">
        <input
          class="toggle"
          type="checkbox"
          :checked="item.isDone"
          @change="change(item.id)"
        />
        <label>{{ item.name }}</label>
        <button class="destroy" @click="del(item.id)"></button>
      </div>
    </li>
  </ul>
</template>

<script>
export default {
  props: {
    list: {
      type: Array, //效验类型为数组
      required: true, //代表必传
    },
  },
  methods: {
    // 把itme.id子传父传给父组件
    del(id) {
      this.$emit('delFn', id)
    },
    change(id) {
      // change事件  发生改变是触发
      // 将当前项的id传给组件
      this.$emit('changeFn', id)
    },
  },
}
</script>
